home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / SampleCollections.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-11  |  4.6 KB  |  242 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Collections.h
  3.  
  4.     Contains:    Sample collection functions & classes
  5.  
  6.     Written by:    Steve Smith
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Description:
  11.                 CList: Generic unordered list
  12.                 COrderedList: Generic ordered list
  13.                 CFrameList: Unordered list of frames -
  14.                             frames automatically refcounted when 
  15.                             added/removed from list.
  16.                 CQueue: Generic queue collection
  17.                 CStack: Generic stack collection
  18. */
  19.  
  20.  
  21. #ifndef _SAMPLECOLLECTIONS_
  22. #define _SAMPLECOLLECTIONS_
  23.  
  24. // --- OpenDoc Includes ---
  25.  
  26. #ifndef _ODTYPES_
  27. #include <ODTypes.h>
  28. #endif
  29.  
  30. #ifndef SOM_ODFrame_xh
  31. #include <Frame.xh>
  32. #endif
  33.  
  34. // --- OpenDoc Utilities ---
  35.  
  36. #ifndef _ODNEW_
  37. #include <ODNew.h>
  38. #endif
  39.  
  40. #ifndef _LINKLIST_
  41. #include "LinkList.h"
  42. #endif
  43.  
  44. //------------------------------------------------------------------------------
  45. // Classes Defined by this Interface
  46. //------------------------------------------------------------------------------
  47.  
  48. class CList;
  49. class CListIterator;
  50. class COrderedList;
  51. class COrdListIterator;
  52. class CFrameList;
  53. class CFrameListIterator;
  54. class CQueue;
  55. class CStack;
  56.  
  57. //------------------------------------------------------------------------------
  58. // Forwards
  59. //------------------------------------------------------------------------------
  60.  
  61. enum {
  62.     kItemNotFound = -1,
  63.     kListIsEmpty = 0
  64. };
  65.  
  66. //------------------------------------------------------------------------------
  67. // Collection Class Definitions
  68. //------------------------------------------------------------------------------
  69.  
  70. class CGenericLink: public Link {
  71.     public:
  72.     CGenericLink();
  73.     CGenericLink(void* value);
  74.     virtual ~CGenericLink();
  75.     
  76.     void*    GetValue();
  77.     void    SetValue(void* value);
  78.     
  79.     protected:
  80.     void*    fValue;
  81. };
  82.  
  83. class CFrameLink : public CGenericLink {
  84.     
  85.     public:
  86.     CFrameLink();
  87.     CFrameLink(ODFrame* frame);
  88.     virtual ~CFrameLink();
  89.         
  90.     ODFrame*    GetFrame();
  91.     void        SetFrame(ODFrame* frame);
  92. };
  93.  
  94.  
  95. class CList {
  96.     public:
  97.     CList();
  98.     virtual ~CList();
  99.  
  100.       ODBoolean    IsEmpty() const;
  101.     ODULong        Count() const;
  102.       ODBoolean    Contains(const void* value);
  103.       void        DeleteAllLinks();
  104.       void        RemoveAllLinks();
  105.       void        Delete(void* value);
  106.       void        Remove(void* value);
  107.       void        Add(void* value);
  108.             
  109.       private:
  110.       LinkedList        fList;
  111.       
  112.       friend class CListIterator;
  113. };
  114.  
  115. class CListIterator {
  116.     public:
  117.     CListIterator() {}
  118.     CListIterator(CList* list);
  119.     virtual ~CListIterator();
  120.         
  121.     void*        First();
  122.     void*        Next();
  123.     void*        Previous();
  124.     void*        Last();
  125.     void*        Current();
  126.     ODBoolean     IsNotComplete();
  127.     void        RemoveCurrent();
  128.     void        DeleteCurrent();
  129.  
  130.     protected:
  131.     LinkedListIterator*    fIter;
  132. };
  133.  
  134.  
  135. class COrderedList {
  136.     public:
  137.     COrderedList();
  138.     COrderedList(COrderedList *list);
  139.     virtual ~COrderedList();
  140.  
  141.       ODBoolean    IsEmpty() const;
  142.     ODULong        Count() const;
  143.       ODBoolean    Contains(const void* value);
  144.       ODUShort    Position(const void* value);
  145.       void        DeleteAllLinks();
  146.       void        RemoveAllLinks();
  147.       void        Delete(void* valeu);
  148.       void        Remove(void* value);
  149.       void*        RemoveFirst();
  150.       void*        RemoveLast();
  151.       void        AddBefore(const void* existing, void* value);
  152.       void        AddAfter(const void* existing, void* value);
  153.       void        AddFirst(void* value);
  154.       void        AddLast(void* value);
  155.       void*        After(const void* value) const;
  156.       void*        Before(const void* value) const;
  157.       void*        First() const;
  158.       void*        Last() const;
  159.             
  160.       private:
  161.       LinkedList        fList;
  162.       
  163.       friend class COrdListIterator;
  164. };
  165.  
  166. class COrdListIterator : public CListIterator {
  167.     public:
  168.     COrdListIterator(COrderedList* list);
  169.     virtual ~COrdListIterator();
  170. };
  171.  
  172.  
  173. class CFrameList {
  174.     public:
  175.     CFrameList();
  176.     virtual ~CFrameList();
  177.  
  178.       ODBoolean    IsEmpty() const;
  179.     ODULong        Count() const;
  180.       ODBoolean    Contains(const ODFrame* frame);
  181.       void        Remove(ODFrame* frame);
  182.       void        Add(ODFrame* frame);
  183.       ODFrame*    GetFrame();
  184.       
  185.       private:
  186.       LinkedList        fList;
  187.       
  188.       friend class CFrameListIterator;
  189. };
  190.  
  191. class CFrameListIterator {
  192.     public:
  193.     CFrameListIterator(CFrameList* list);
  194.     ~CFrameListIterator();
  195.         
  196.     ODFrame*    First();
  197.     ODFrame*    Next();
  198.     ODFrame*    Previous();
  199.     ODFrame*    Last();
  200.     ODFrame*    Current();
  201.     ODBoolean     IsNotComplete();
  202.     void        ReleaseCurrent();
  203.  
  204.     private:
  205.     LinkedListIterator*    fIter;
  206. };
  207.  
  208. class CStack {
  209.     public:
  210.     CStack();
  211.     ~CStack();
  212.     
  213.     ODBoolean    IsEmpty();
  214.     void        EmptyStack(ODBoolean deleteEntries = kODFalse);
  215.     ODUShort    SetSize(ODUShort maxDepth);
  216.     ODBoolean    PushEntry(void* entry);
  217.     void*        PopEntry();
  218.     
  219.     private:
  220.     ODUShort        fMaxDepth;
  221.     LinkedList        fStack;
  222. };
  223.  
  224. class CQueue {
  225.     public:
  226.     CQueue();
  227.     ~CQueue();
  228.  
  229.     ODBoolean    IsEmpty();
  230.     void        EmptyQueue(ODBoolean deleteEntries = kODFalse);
  231.     ODUShort    SetSize(ODUShort maxEntries);
  232.     ODBoolean    AddEntry(void* entry);
  233.     void*        GetEntry();
  234.     
  235.     private:
  236.     ODUShort        fMaxEntries;
  237.     LinkedList        fQueue;
  238. };
  239.  
  240. #endif //_SAMPLECOLLECTIONS_
  241.  
  242.